<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>模板</title>
  </head>
  <body>
    <!-- 准备好一个容器 -->
    <div id="test"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM -->
    <script
      type="text/javascript"
      src="../js/react-dom.development.js"
    ></script>
    <!-- 引入babel，用于将jsx转换成js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入属性校验js -->
    <script src="../js/prop-types.js" type="text/javascript"></script>
    <script type="text/babel">
      //1.创建组件
      function Person(props) {
        const { name, sex, age } = props;
        return (
          <ul>
            <li>姓名:{name}</li>
            <li>性别:{sex}</li>
            <li>年龄:{age}</li>
          </ul>
        );
      }
      //对标签属性进行类型、必要性的限制
      Person.propTypes = {
        name: PropTypes.string.isRequired, //限制name必传,并且是字符串
        sex: PropTypes.string, //限制sex非必传,且为字符串
        age: PropTypes.number, //限制age非必传,且为数字
      };

      //指定默认标签属性值
      Person.defaultProps = {
        // age: 22, //设置年龄的默认值为22
        // birth: "生日啦",
        name: "sss",
      };
      ReactDOM.render(
        <Person sex="女" age={20} />,
        document.querySelector("#test")
      );
    </script>
  </body>
</html>
